home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mush-7.1.1 / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-02  |  5.3 KB  |  223 lines

  1. /* @(#)print.c    2.4    (c) copyright 10/15/86 (Dan Heller) */
  2.  
  3. #include "mush.h"
  4. #include <varargs.h>
  5.  
  6. /*ARGSUSED*/
  7. /*VARARGS1*/
  8. void
  9. error(fmt, arg1, arg2, arg3, arg4)
  10. register char *fmt;
  11. char *arg1, *arg2, *arg3, *arg4;
  12. {
  13.     char buf[BUFSIZ];
  14.  
  15.     (void) sprintf(buf, fmt, arg1, arg2, arg3, arg4);
  16.     sprintf(buf+strlen(buf), ": %s\n", sys_errlist[errno]);
  17. #ifdef SUNTOOL
  18.     if (istool > 1)
  19.     ok_box(buf);
  20.     else
  21. #endif /* SUNTOOL */
  22.     print(buf);
  23. }
  24.  
  25. #if defined(SUNTOOL) || defined(CURSES)
  26. /*
  27.  * print just like printf -- to a window, to curses, or to stdout.  Use vprintf
  28.  * if available.  msgbuf is the buffer used to print into if necessary.
  29.  * If you're running SUN3.2 or higher, the typecast (unsigned char *)msgbuf
  30.  * (where indicated) otherwise, msgbuf is not typecast at all.
  31.  */
  32. /*VARARGS*/
  33. void
  34. print(va_alist)
  35. va_dcl
  36. {
  37.     static char msgbuf[BUFSIZ];
  38.     char *fmt;
  39.     va_list args;
  40. #ifndef VPRINTF
  41.     FILE foo;
  42. #endif /* VPRINTF */
  43.     static int x; /* position on line saved for continued prints */
  44.     char *p; /* same type as struct file _ptr,_buf in stdio.h */
  45.  
  46. #ifdef CURSES
  47.     if (iscurses) {
  48.     if (isoff(glob_flags, CONT_PRNT))
  49.         move(LINES-1, x = 0), refresh();
  50.     } else
  51. #endif /* CURSES */
  52.     if (istool < 2) {
  53.         va_start(args);
  54.         fmt = va_arg(args, char *);
  55. #ifdef VPRINTF
  56.         (void) vprintf(fmt, args);
  57. #else /* VPRINTF */
  58.         _doprnt(fmt, args, stdout);
  59. #endif /* VPRINTF */
  60.         va_end(args);
  61.         (void) fflush(stdout);
  62.         return;
  63.     }
  64.     va_start(args);
  65.     fmt = va_arg(args, char *);
  66.     if (fmt) {
  67. #ifdef VPRINTF
  68.     (void) vsprintf(msgbuf, fmt, args); /* NULL in fmt reprints last msg */
  69. #else /* VPRINTF */
  70.     foo._cnt = BUFSIZ;
  71.     foo._base = foo._ptr = msgbuf; /* may have to cast(unsigned char *) */
  72.     foo._flag = _IOWRT+_IOSTRG;
  73.     (void) _doprnt(fmt, args, &foo);
  74.     *foo._ptr = '\0'; /* plant terminating null character */
  75. #endif /* VPRINTF */
  76.     }
  77.     va_end(args);
  78.     if (istool) {
  79.     wprint("%s", msgbuf);
  80.     return;
  81.     }
  82.     p = msgbuf;
  83.     if (iscurses)
  84.     while (p = index(p, '\n'))
  85.         *p = ' ';
  86. #ifdef CURSES
  87.     if (iscurses) {
  88.     p = msgbuf;
  89.     for (;;) {
  90.         int len = COLS-1-x; /* space remaining at till the eol */
  91.         /* don't wrap the line! Just print it and refresh() */
  92.         printw("%-.*s", len, p), clrtoeol(), refresh();
  93.         /* if length(p) (remainder of msgbuf) doesn't wrap, break loop */
  94.         if ((x += strlen(p)) < COLS-1)
  95.         break;
  96.         /* the next print will overwrite bottom line, so \n first */
  97.         putchar('\n'), move(LINES-1, x = 0); /* reset x */
  98.         /* move p forward the number of chars we were able to display */
  99.         p += len;
  100.         turnon(glob_flags, CNTD_CMD); /* display ...continue... prompt */
  101.     }
  102.     turnoff(glob_flags, CONT_PRNT);
  103.     (void) fflush(stdout); /* some sys-v's aren't fflushing \n's */
  104.     return;
  105.     }
  106. #endif /* CURSES */
  107. }
  108.  
  109. #endif /* SUNTOOL || CURSES */
  110.  
  111. /* for curses mode */
  112. clr_bot_line()
  113. {
  114.     print("");
  115. }
  116.  
  117. #ifdef SUNTOOL
  118.  
  119. /*
  120.  * wprint prints stuff to a scrollable textsw.  This is intended for
  121.  * print statements that need to be recalled since print() overwrites
  122.  * its last message.  Messages are printed to whatever wprint_sw
  123.  * currently points to.  If you set it to null, nothing prints.
  124.  * For non-suntool mode, wprint() is just like printf().  For curses mode,
  125.  * wprint() does -not- act like print() -- lines length is not counted
  126.  * and newlines are not stripped.
  127.  */
  128. /*VARARGS*/
  129. void
  130. wprint(va_alist)
  131. va_dcl
  132. {
  133. #ifndef VPRINTF
  134.     FILE foo;
  135. #endif /* VPRINTF */
  136.     char msgbuf[BUFSIZ]; /* we're not getting huge strings */
  137.     char *fmt;
  138.     va_list args;
  139.  
  140.     if (istool < 2) {
  141.     va_start(args);
  142.     fmt = va_arg(args, char *);
  143. #ifdef VPRINTF
  144.     (void) vprintf(fmt, args);
  145. #else /* VPRINTF */
  146.     _doprnt(fmt, args, stdout);
  147. #endif /* VPRINTF */
  148.     va_end(args);
  149.     (void) fflush(stdout);
  150.     return;
  151.     }
  152.     if (!compose_frame || !window_get(compose_frame, WIN_SHOW) || !cprint_sw)
  153.         wprint_sw = mfprint_sw;
  154.     else
  155.         wprint_sw = cprint_sw;
  156.  
  157.     if (!wprint_sw)
  158.         return;
  159.     va_start(args);
  160.     fmt = va_arg(args, char *);
  161.     if (fmt) {
  162. #ifdef VPRINTF
  163.     (void) vsprintf(msgbuf, fmt, args); /* NULL in fmt reprints last msg */
  164. #else /* VPRINTF */
  165.     foo._cnt = BUFSIZ;
  166.     foo._base = foo._ptr = msgbuf; /* may have to cast (unsigned char *) */
  167.     foo._flag = _IOWRT+_IOSTRG;
  168.     _doprnt(fmt, args, &foo); /* format like printf into msgbuf via foo */
  169.     *foo._ptr = '\0'; /* plant terminating null character */
  170. #endif /* VPRINTF */
  171.     textsw_insert(wprint_sw, msgbuf, strlen(msgbuf));
  172.     }
  173.     va_end(args);
  174. }
  175.  
  176. #include <sundev/kbio.h>
  177. #include <sundev/kbd.h>
  178.  
  179. bell()
  180. {
  181. #ifdef KIOCCMD
  182.     if (istool) {
  183.     int kbd = open("/dev/kbd", O_WRONLY, 0);
  184.     struct timeval timer;
  185.     timer.tv_sec = 0;
  186.     timer.tv_usec = 100000;
  187.     if (kbd != -1) {
  188.         int cmd = KBD_CMD_BELL;
  189.         (void) ioctl(kbd, KIOCCMD, &cmd);
  190.         (void) select(32, (fd_set *) 0,(fd_set *) 0,(fd_set *) 0, &timer);
  191.         cmd = KBD_CMD_NOBELL;
  192.         (void) ioctl(kbd, KIOCCMD, &cmd);
  193.         (void) close(kbd);
  194.     }
  195.     } else
  196. #endif /* KIOCCMD */
  197.     (void) fputc('\007', stderr), (void) fflush(stderr);
  198.     return 0;
  199. }
  200.  
  201. #endif /* SUNTOOL */
  202.  
  203. #ifdef BSD
  204. #undef fputs
  205.  
  206. /*
  207.  * The standard 4.x BSD fputs() does not return any useful value.
  208.  * For compatibility with Sun and SysV fputs(), we use this wrapper.
  209.  */
  210.  
  211. Fputs(line, fp)
  212. char *line;
  213. FILE *fp;
  214. {
  215.     clearerr(fp);
  216.     (void) fputs(line, fp);
  217.     if (ferror(fp))
  218.     return EOF;
  219.     return 0;
  220. }
  221.  
  222. #endif /* BSD */
  223.